﻿using System;
using TaleWorlds.MountAndBlade;

namespace MarriageFertility.Missions;

public class CheerActionHandler
{
    private readonly ActionIndexCache[] _lowCheerActions = new ActionIndexCache[10]
    {
        ActionIndexCache.Create("act_cheering_low_01"),
        ActionIndexCache.Create("act_cheering_low_02"),
        ActionIndexCache.Create("act_cheering_low_03"),
        ActionIndexCache.Create("act_cheering_low_04"),
        ActionIndexCache.Create("act_cheering_low_05"),
        ActionIndexCache.Create("act_cheering_low_06"),
        ActionIndexCache.Create("act_cheering_low_07"),
        ActionIndexCache.Create("act_cheering_low_08"),
        ActionIndexCache.Create("act_cheering_low_09"),
        ActionIndexCache.Create("act_cheering_low_10")
    };

    private readonly ActionIndexCache[] _midCheerActions = new ActionIndexCache[4]
    {
        ActionIndexCache.Create("act_cheer_1"),
        ActionIndexCache.Create("act_cheer_2"),
        ActionIndexCache.Create("act_cheer_3"),
        ActionIndexCache.Create("act_cheer_4")
    };

    private readonly ActionIndexCache[] _highCheerActions = new ActionIndexCache[8]
    {
        ActionIndexCache.Create("act_cheering_high_01"),
        ActionIndexCache.Create("act_cheering_high_02"),
        ActionIndexCache.Create("act_cheering_high_03"),
        ActionIndexCache.Create("act_cheering_high_04"),
        ActionIndexCache.Create("act_cheering_high_05"),
        ActionIndexCache.Create("act_cheering_high_06"),
        ActionIndexCache.Create("act_cheering_high_07"),
        ActionIndexCache.Create("act_cheering_high_08")
    };

    private ActionIndexCache[] _allCheerActions;

    public CheerActionHandler()
    {
        // 合并所有欢呼动作到一个数组
        _allCheerActions = MergeCheerActions();
    }

    // 合并所有动作
    private ActionIndexCache[] MergeCheerActions()
    {
        int totalLength = _lowCheerActions.Length + _midCheerActions.Length + _highCheerActions.Length;
        ActionIndexCache[] mergedActions = new ActionIndexCache[totalLength];

        _lowCheerActions.CopyTo(mergedActions, 0);
        _midCheerActions.CopyTo(mergedActions, _lowCheerActions.Length);
        _highCheerActions.CopyTo(mergedActions, _lowCheerActions.Length + _midCheerActions.Length);

        return mergedActions;
    }

    // 随机获取一个欢呼动作
    public ActionIndexCache GetRandomCheerAction()
    {
        Random random = new Random();
        int randomIndex = random.Next(0, _allCheerActions.Length); // 获取随机索引
        return _allCheerActions[randomIndex]; // 返回随机动作
    }
}